{% extends "base.html" %}
{% from 'macros.html' import form_field %}
<!-- {% import "bootstrap/wtf.html" as wtf %} -->
<!-- using wtf.html will influence the network speed -->

{% block title %}ddl-web{% endblock %}



<div class="page-header">
    <h1>Hello, {% if name %}{{ name }}{% else %}Stranger{% endif %}!</h1>
    {% if not known %}
    <p>Pleased to meet you!</p>
    {% else %}
    <p>Happy to see you again!</p>
    {% endif %}
</div>

{% block page_content %}
{% block navbar %}
<div class="navbar navbar-inverse" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle"
            data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/">ddl-web</a>
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li><a href="/">Home</a></li>
                <li><a href="{{ url_for('main.logout') }}">Logout</a></li>
            </ul>
        </div>
    </div>
</div>
{% endblock %}
<div class="page-header">
    <h1>Hello, {% if name %}{{ name }}{% else %}Stranger{% endif %}!</h1>
    {% if not known %}
    <p>Pleased to meet you!</p>
    {% else %}
    <p>Happy to see you again!</p>
    {% endif %}
</div>

<h3>Query dataset</h3>    
<form method="post" action="{{ url_for('main.query_dataset') }}">
    {{ form_query_dataset.csrf_token }}
    {{ form_field(form_query_dataset.name) }}
    {{ form_query_dataset.submit }}
</form>
{% if query_dataset %}
<table border="1">
    <tr>
    <th>Supporting Datasets</th>
    </tr>
    {% for col in datasets  %}
        <tr>
        <td>{{ col }}</td>
        <!-- <td>row 1, cell 2</td> -->
        </tr>
    {% endfor %}
</table>
{% endif %}

<h3>submit your code</h3>
<form method="post" action="{{ url_for('main.submit_job') }}" enctype=multipart/form-data>
    {{ form_submit_job.csrf_token }}
    {{ form_field(form_submit_job.name)}}
    {{ form_submit_job.job_code}}
    <!-- {{ form_field(form_submit_job.job_code)}} -->
    <!-- <input type="file" name="my_file"> -->
    {{ form_submit_job.submit }}
</form>

<h3>query job</h3>
<form method="post" action="{{ url_for('main.query_job') }}">
    {{ form_query_job.csrf_token }}
    {{ form_field(form_query_job.name) }}
    {{ form_field(form_query_job.job_id) }}
    {{ form_query_job.submit }}
</form>
{% if query_job %}
<h5>Running Jobs:
</h5>
<table border="1">
    <tr>
    <th>Job ID</th>
    <th>User Name</th>
    <th>Code Dir</th>
    <th>Status</th>
    <th>Process ID</th>    
    </tr>
    {% for col in jobs  %}
        <tr>
        <td>{{ col['jobid'] }}</td>
        <td>{{ col['username'] }}</td>
        <td>{{ col['codedir'] }}</td>
        <td>{{ col['status'] }}</td>
        <td>{{ col['process'] }}</td>
        </tr>
    {% endfor %}
</table>
{% endif %}

<h3>Query Resources</h3>
<form method="post" action="{{ url_for('main.query_resource') }}">
    {{ form_query_resource.csrf_token }}
    {{ form_field(form_query_resource.name) }}
    {{ form_query_resource.submit }}
</form>

{% if query_resource %}
<h5>Running Jobs:
</h5>
<table border="1">
    <tr>
    <th>Node ID</th>
    <th>GPU ID</th>
    <th>Num of Jobs</th>
    <th>Available mem</th>
    <th>Jobs ID</th>    
    </tr>
    {% for col in resources  %}
        <tr>
        <td>{{ col['nodeid'] }}</td>
        <td>{{ col['gpuid'] }}</td>
        <td>{{ col['num_jobs'] }}</td>
        <td>{{ col['available_mem'] }}</td>
        <td>{{ col['jobids'] }}</td>
        </tr>
    {% endfor %}
</table>
{% endif %}


<!-- {{ wtf.quick_form(form_create_user, id='form_create_user', action="{{ url_for('create_user') }}") }}
{{ wtf.quick_form(form_query_dataset, id='form_query_dataset', action="{{ url_for('query_dataset') }}") }}
{{ wtf.quick_form(form_submit_job, id='form_submit_job', action="{{ url_for('submit_job') }}") }}
{{ wtf.quick_form(form_query_job, id='form_query_job', action="{{ url_for('query_job') }}") }}
{{ wtf.quick_form(form_kill_job, id='form_kill_job', action="{{ url_for('kill_job') }}") }} -->
{% endblock %}

